package leetcode_100;

import java.util.ArrayList;
import java.util.List;

/**
 *@author 周杨
 *LetterCombinationsOfAPhoneNumber_17 一个电话
 *describe:
 *2018年12月21日 下午9:02:25
 */
public class LetterCombinationsOfAPhoneNumber_17 {
	public List<String> letterCombinations(String digits) {
		if(digits==null||digits.length()==0) return new ArrayList<String>();
        char [][]map=new char[][] {{},{},{'a','b','c'},
        	{'d','e','f'},{'g','h','i'},{'j','k','l'},
        	{'m','n','o'},{'p','q','r','s'},{'t','u','v'},{'w','x','y','z'}};
        char []chars=digits.toCharArray();
        char []now=new char[chars.length];
        List<String> res=new ArrayList<String>();
        help(now,res,chars,0,map);
        return res;
    }
	
	public void help(char[] now,List<String> res,char[] chars,int index,char[][] map) {
		if(index==chars.length) {
			res.add(new String(now)); 
			return ;
		}
		int find=chars[index]-'0';
		for(int i=0;i<map[find].length;++i) {
			now[index]=map[find][i];
			help(now,res,chars,index+1,map);
		}
	}
}
